<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
    <h3>小黑的书架</h3>
    <ul>
        <li :key="item.id" v-for="(item,index) in booksList">
            <span>{{item.name}}</span>
            <span>{{item.author}}</span>
            <button @click="del(item.id)">删除</button>
        </li>
    </ul>
</div>

<script src="../vue.global.js"></script>

<script>
    const {createApp, ref} = Vue;
    createApp({
        setup() {
            const booksList = ref([
                {id: 1, name: "《红楼梦》", author: "曹雪芹"},
                {id: 2, name: "《三国演义》", author: "罗贯中"},
                {id: 3, name: "《西游记》", author: "吴承恩"},
                {id: 4, name: "《水浒传》", author: "施耐庵"}
            ]);

            const del = (id) => {
                booksList.value = booksList.value.filter(item => item.id !== id);
            }
            return {booksList, del};
        }
    }).mount('#app');
</script>


</body>
</html>